{extend name="layout/base"}

{block name="content"}
<div class="login_box">
    <div class="login_logo">
        <img src="/static/images/logo.jpeg" alt="">
    </div>
    <!--<h3>内蒙古安全健康教育</h3>-->
    <div class="login-form">
        <form action="" method="post" class="layui-form layui-form-pane" layui->
            <!--<h2>登陆</h2>-->
            <div class="layui-form-item">
                <label class="layui-form-label" for="username">用户名：</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" id="username" name="username" autocomplete="off" lay-verify="require">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label" for="password">密码：</label>
                <div class="layui-input-block">
                    <input type="password" class="layui-input" id="password" name="password">
                </div>
            </div>
            <div class="layui-form-item layui-block">
                <div class="layui-input-inline login_button">
                    <button type="submit" lay-submit lay-filter="login" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal">登陆</button>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="login_bottom">技术支持：内蒙古嘉易网络科技有限公司</div>

<script>
    layui.use(['jquery', 'form'], function ($, form) {
        form.on('submit(login)', function (obj) {
            $.ajax({
                url: "{:url('login')}",
                data: obj.field,
                type: 'post',
                success: function (response) {
                    var p = Number(response.code) === 0;
                    layer.msg(response.msg || '请求成功', {
                        icon: p ? 6 : 5
                    }, function () {
                        p && location.replace(url)
                    });
                    var data = response.data || {},
                        url = response.url;
                    typeof callback === 'function' && data && callback(data);
                },
                error: function () {
                    layer.msg('请求错误', {icon: 5});
                }
            });
            return false;
        });
    });
</script>
{/block}